package com.yx.fmmall.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @Classname MD5Utils
 * @Date 2022/01/16 16:56
 * @Author by yx
 * @Description : MD5加密生成器
 */
public class MD5Utils {
    public static String md5(String password){
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            // 计算MD5的值
            messageDigest.update(password.getBytes());
            // BigInteger 将8位字符串转换位16位,得到的字符串形式是哈希码
            // BigInteger(参数1,参数2) 参数1->1正数,0为0.-1为负数
            return new BigInteger(1,messageDigest.digest()).toString(16);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
}
